
class HouseItem:
    def __init__(self,name,area):
        self.name = name
        self.area = area
    def __str__(self):
        return  f"{self.name}占地面积{self.area}"


class House:
    def __init__(self, h_type,area):
        self.h_type = h_type  # 户型
        self.total_area = area # 总⾯积
        self.free_area = area # 剩余⾯积和总⾯积⼀样
        self.item_list = [] # 刚开始没有家具

    def __str__(self):
        return f"户型:{self.h_type}、总⾯积:{self.total_area} 平⽶、剩余⾯积:{self.free_area}平⽶、家具名称列表:{self.item_list}"

    def add_item(self, item):
        if self.free_area > item.area:
            print(f'添加家具: {item.name}')
            self.item_list.append(item.name)
            # 修改剩余⾯积
            self.free_area -= item.area
        else:
            print(f"房⼦剩余⾯积不⾜,换个⼤房⼦吧.....")

if __name__ == '__main__':
    # 创建家具对象
    bed = HouseItem('席梦思', 4)
    chest = HouseItem('⾐柜', 2)
    table = HouseItem('餐桌', 1.5)
    print(bed)
    print(chest)
    print(table)
    # 创建房⼦
    house = House('三室⼀厅', 100)
    print(house)
    house.add_item(bed)
    print(house)
    house.add_item(chest)
    print(house)
    house.add_item(table)
    print(house)